﻿using Hotel.WCF.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using Hotel.Models;
using System.Data.SqlClient;
using System.Configuration;
using Hotel.Models;

namespace Hotel.WCF.ImpServices
{
    public partial class GestionHotel : IHotel
    {
        private Chaine_Hotels _ch;
        //ContexteDAO context;

        //ajout d'une chaîne d'hotel
        public int AddChaineHotels(Chaine_Hotels ch)
        {
            int res = -1;
            try
            {                
                _ch = new Chaine_Hotels();
                _ch = ch;
                _ch.Ajouter();
                res = 1;
                
            }
            catch (Exception ex)
            {
                res = -1;
                //logger les erreurs
                throw ex;
            }
            
            return res;
        }
        //suppression
        public int deleteChaineHotels(Chaine_Hotels ch)
        {
            int res = -1;
            try
            {
                _ch = new Chaine_Hotels();
                foreach (var item in _ch.GetListeInstances())
                {
                    if (item.ID == ch.ID)
                    {
                        item.Supprimer();
                    }
                }
                //Chaine_Hotels chEncours = (
                //                            from c in _ch.GetListeInstances()
                //                            where c.ID == ch.ID
                //                            select c
                //                            );

                //chEncours.Supprimer();
                
                res = 1;

            }
            catch (Exception ex)
            {
                res = -1;
                //logger les erreurs
                throw ex;
            }

            return res;
        }

        //affichage des chaine d'hotels
        public  List<Chaine_Hotels> getListChaineHotels()
        {
            _ch = new Chaine_Hotels();
            return _ch.GetListeInstances();
        }

    }
}